<?php
class View_Product extends View_Admin_Index_Template {
    public $oTemp;
    public $userID;
    public function __construct($oModel) {
    }
    public function showAttributeAjax($oModel,$product_id) {
        $currentA = $oModel->getParrentAttOfItemProduct($product_id);
        $allParrent = $oModel->getAllAttParr();
        $allChildAttDet = $oModel->getAllAttDet();
        $aAtribute = array();
        if (is_array($allParrent)) {
            foreach ($allParrent as $tabberParrent)//with each parrent we will parse cild and select once child
            {
                if (is_array($allChildAttDet)) {
                    foreach ($allChildAttDet as $childAtribute) {
                        $childAtribute['at_name'] = $tabberParrent['at_name'];
                        if ($childAtribute['at_id']==$tabberParrent['at_id']) {
                            if (is_array($currentA)) {
                                foreach ($currentA as $itemCurrent) {
                                //													echo ($itemCurrent['atd_id']."  ". $childAtribute['atd_id']." %");
                                    if ($itemCurrent['atd_id'] == $childAtribute['atd_id']) {
                                        $variable = 'parent_att'.$itemCurrent['at_id'];
                                        $aAtribute[$variable]=$itemCurrent['atd_id'];

                                    }
                                }
                            }

                        }

                    //
                }// end foreach

            }// end if


        }// end foreach
        }// end if
        return $aAtribute;

    }
    public function showAttributeAddNew($oModel) {
        $allParrent = $oModel->getAllAttParr();
        $allChildAttDet = $oModel->getAllAttDet();
        if (is_array($allParrent)) {
            $num=0;
            foreach ($allParrent as $tabberParrent)//with each parrent we will parse cild and select once child
            {
                if (is_array($allChildAttDet)) {
                    foreach ($allChildAttDet as $childAtribute) {
                        $childAtribute['at_name'] = $tabberParrent['at_name'];
                        if ($childAtribute['at_id']==$tabberParrent['at_id']) {
                            $this->oTemp->assign('LIST_CHILD_ATT',$childAtribute);
                            $this->oTemp->parse('main.PARRENT_ATTRIBUTE_II.LIST_CHILD_ATT');
                        }
                }// end foreach

                }// end if
                if($num==0)
                    $tabberParrent['checked']='checked';

                $num++;
                $this->oTemp->assign('PARRENT_ATTRIBUTE',$tabberParrent);
                $this->oTemp->parse('main.PARRENT_ATTRIBUTE');
                $this->oTemp->parse('main.PARRENT_ATTRIBUTE_II');
        }// end foreach
    }// end if

    }
    public function showAttribute($oModel,$product_id) {
        $currentA = $oModel->getParrentAttOfItemProduct($product_id);
        $allParrent = $oModel->getAllAttParr();
        $allChildAttDet = $oModel->getAllAttDet();
        if (is_array($allParrent)) {
            foreach ($allParrent as $tabberParrent)//with each parrent we will parse cild and select once child
            {
                if (is_array($allChildAttDet)) {
                    foreach ($allChildAttDet as $childAtribute) {
                        $childAtribute['at_name'] = $tabberParrent['at_name'];
                        if ($childAtribute['at_id']==$tabberParrent['at_id']) {
                            if (is_array($currentA)) {
                                foreach ($currentA as $itemCurrent) {
                                    if ($itemCurrent['atd_id'] == $childAtribute['atd_id']) {
                                        $childAtribute['checked'] = 'checked';
                                    }
                                }
                            }
                            $this->oTemp->assign('LIST_CHILD_ATT',$childAtribute);
                            $this->oTemp->parse('main.PARRENT_ATTRIBUTE_II.LIST_CHILD_ATT');
                        }

                    //
                }// end foreach

                }// end if
                $this->oTemp->assign('PARRENT_ATTRIBUTE',$tabberParrent);
                $this->oTemp->parse('main.PARRENT_ATTRIBUTE');
                $this->oTemp->parse('main.PARRENT_ATTRIBUTE_II');
        }// end foreach
    }// end if


    }

    public function ajax_showChildAtt($oModel,$product_id) {
        $rs=$oModel->getParrentAttOfItemProduct($product_id);
        $arr=array();
        if(is_array($rs)) {
            foreach($rs as $row) {
                $arr[]=$row['atd_id'];
            }
            return $arr;
        }
        else
            return null;
    }
    public function displayManagerIndex($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/product_index.html' );
        $this->oTemp->assign_file( 'search_and_filter_block', PATH_TEMPLATE_ADMIN.'html/filter_block.html' );
        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['product_detail']);

        $this->oTemp->assign('toobar_delete','delete_products()');
        $this->oTemp->parse('main.toobar_delete');
        $this->oTemp->assign('toobar_save',"doUpdateProducts()");
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_download',"export_csv();");
        $this->oTemp->parse('main.toobar_download');
        $this->oTemp->assign('toobar_find_product',"?sMod=product_index&sAction=find_product_form");
        $this->oTemp->parse('main.toobar_find_product');
    }

    public function IndexLoadHTMLUpdateSize($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/update_size.html' );
    //		$this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['product_detail']);
    }
    public function ajaxGetCurrentAtr($oModel,$product_id) {
        $currentA = $oModel->getParrentAttOfItemProduct($product_id);
        $allParrent = $oModel->getAllAttParr();
        $allChildAttDet = $oModel->getAllAttDet();

        if (is_array($currentA)) {

            foreach ($currentA as $item) {
                if (is_array($allParrent)) {
                    foreach ($allParrent as $parr) {
                        if($item['at_id']==$parr['at_id'])
                            $parr['selected']='selected';
                        $this->oTemp->assign("BLOCK_II",$parr);
                        $this->oTemp->parse('main.BLOCK_I.BLOCK_II');
                    }
                }

                if (is_array($allChildAttDet)) {
                    foreach ($allChildAttDet as $child) {
                        if ($child['at_id']==$item['at_id']) {
                            if($item['atd_id']==$child['atd_id'])
                                $child['selected']='selected';
                            $this->oTemp->assign("BLOCK_CHILD",$child);
                            $this->oTemp->parse('main.BLOCK_I.BLOCK_CHILD');
                        }
                    }

                }

                $this->oTemp->parse('main.BLOCK_I');


            }
            $RES = $this->oTemp->text('main.BLOCK_I');
        }
        $oJSON = new Services_JSON() ;
        echo $oJSON->encode( array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m'), ),
        'BODY' => array('RES' => $RES
        )) ) ;

    }

    public function display_csv($oModel) {
        $this->initTemplate($oModel);
    }

    public function displayListOwner($oModel,$isAllowAdmin = false){
        if($_SESSION['admin_role']==3){
            $this->userID = $_SESSION['admin_id'];
        }
        else{
            $rs = $oModel->getAllShopOwner();
            if(isset($_GET['user_id'])){
                $this->userID = $_GET['user_id'];
            }
            else{
                $this->userID = 0;
            }
            foreach($rs as $row){
                if($this->userID==0 && !$isAllowAdmin){
                    $this->userID = $row['admin_id'];
                }
                if($row['admin_id']==$this->userID){
                    $row['selected'] = 'selected="selected"';
                }
                else{
                    $row['selected'] = "";
                }
                $this->oTemp->assign("admin",$row);
                $this->oTemp->parse("main.shop_owner_role.shop_owner");
            }
            $this->oTemp->parse("main.shop_owner_role");
        }
    }
    public function displayListProduct($oModel){
        $arrayListProduct = $oModel->getListProduct($this->userID);
        $this->oTemp->assign("page",$_REQUEST['pUser']);
        if (is_array($arrayListProduct))

            foreach ($arrayListProduct as $itemProduct) {
                
                if ($itemProduct["product_yahoo_point"]==1 || $itemProduct["product_yahoo_point"]=="1")
                    $itemProduct["product_yahoo_point_checked"] = "checked";
                if ($itemProduct["product_date_added"]=="" || $itemProduct["product_date_added"]== null)
                    $itemProduct["product_date_added"] = "0000-00-00";
                if ($itemProduct["product_icon_gift"]==1 || $itemProduct["product_icon_gift"]=="1")
                    $itemProduct["product_icon_gift_checked"] = "checked";
                if ($itemProduct["product_store_hot_auction"]==1 || $itemProduct["product_store_hot_auction"] == "1")
                    $itemProduct["product_store_hot_auction_checked"] = "checked";
                if ($itemProduct["product_bakground_color"]==1 || $itemProduct["product_bakground_color"] == "1")
                    $itemProduct["product_bakground_color_checked"] = "checked";
                if ($itemProduct["product_title_bold_line"] == 1 || $itemProduct["product_title_bold_line"] == "1")
                    $itemProduct["product_title_bold_line_checked"] = "checked";
                if ($itemProduct["product_have_to_negotiate_discount"]==1 || $itemProduct["product_have_to_negotiate_discount"]=="1")
                    $itemProduct["product_have_to_negotiate_discount_checked"] = "checked";
                if ($itemProduct["product_affiliate"]==1 || $itemProduct["product_affiliate"]=="1")
                    $itemProduct["product_remuneration_to_partner"] = $itemProduct["product_remuneration_to_partner"]."%";
                else
                    $itemProduct["product_remuneration_to_partner"] = "";

                // use yahoo point with fees
                if ($itemProduct["product_yahoo_point"]==1 || $itemProduct["product_yahoo_point"]=="1") {
                    $itemProduct["product_yahoo_point_fees"] = floatval($itemProduct["product_yahoo_point_fees"])."%";
                }
                else
                    $itemProduct["product_yahoo_point_fees"] = "";
                // icon highlight
                if (strlen($itemProduct["product_icon_highlight"])>3) {
                    $itemProduct["product_icon_highlight"] = '<img src="{URL_TEMPLATE_ADMIN}image/icon/'.$itemProduct["product_icon_highlight"].'" title="affiliate" align="middle" border="0"/>';
                }
                else
                    $itemProduct["product_icon_highlight"] = "";

                $product_key_select = $itemProduct['product_key_select'];
                if($product_key_select > 0){
                    $itemProduct['product_key'] = $itemProduct["product_key".$product_key_select];
                }else{
                    $itemProduct['product_key'] = '';
                }

                $doneAll = true;
                if($itemProduct['product_explanation'] == '') {
                    $doneAll=false;
                }

                if($itemProduct['product_picture3'] == '' AND $itemProduct['product_picture2'] == '' AND $itemProduct['product_picture1'] == '') {
                    $doneAll=false;
                }

                if($itemProduct['product_size'] == "") {
                    $doneAll=false;
                }
                if($doneAll) {
                    $itemProduct['stylesheet'] = 'style="background-color:#EEE"';
                }else {
                    $itemProduct['stylesheet']='';
                }

                if($itemProduct['product_picture1'] != ''){
                    if(file_exists(PATH_UPLOAD_PRODUCT.FOLDER_THUMB.$itemProduct['product_picture1'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT_THUMB.$itemProduct['product_picture1'];
                    }elseif(file_exists(PATH_UPLOAD_PRODUCT.$itemProduct['product_picture1'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT.$itemProduct['product_picture1'];
                    }
                }elseif($itemProduct['product_picture2'] != ''){
                    if(file_exists(PATH_UPLOAD_PRODUCT.FOLDER_THUMB.$itemProduct['product_picture2'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT_THUMB.$itemProduct['product_picture2'];
                    }elseif(file_exists(PATH_UPLOAD_PRODUCT.$itemProduct['product_picture2'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT.$itemProduct['product_picture2'];
                    }
                }elseif($itemProduct['product_picture3'] != ''){
                    if(file_exists(PATH_UPLOAD_PRODUCT.FOLDER_THUMB.$itemProduct['product_picture3'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT_THUMB.$itemProduct['product_picture3'];
                    }elseif(file_exists(PATH_UPLOAD_PRODUCT.$itemProduct['product_picture3'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT.$itemProduct['product_picture3'];
                    }
                }else{
                    $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT.'no_image.gif';
                }
                //holy shit, know very bad, but still write :D
				$sql_new = "SELECT * FROM ams_product_defaul WHERE 1 = 1";
				$rs_new = mysql_query($sql_new);
				$row_new = mysql_fetch_array($rs_new);
				//echo $row_new['product_price'];
				if($itemProduct['product_prices_start'] == "") $itemProduct['product_prices_start'] = $row_new['product_price'];
				if($itemProduct['product_qty'] == "") $itemProduct['product_qty'] = $row_new['product_qty'];
				if($itemProduct['product_time_auction'] == "") $itemProduct['product_time_auction'] = $row_new['product_time_auction'];
				if($itemProduct['product_time_auction_end'] == "") $itemProduct['product_time_auction_end'] = $row_new['product_time_auction_end'];
				//echo $itemProduct['product_prices_start']."xxx";
                $this->oTemp->assign("rowProduct",$itemProduct);
                $this->oTemp->parse('main.LIST_PRODUCT.rowProduct');
            }
        $this->oTemp->parse('main.LIST_PRODUCT');
        $this->oTemp->assign("navigator",$oModel->oNavigator->navigator());
    }
    public function viewListProvince($oModel) {
        $arrayListProvince = $oModel->getListProvince();
        if (is_array($arrayListProvince))
            foreach ($arrayListProvince as $itemProduct) {
                $this->oTemp->assign("PROVINCE",$itemProduct);
                $this->oTemp->parse('main.PROVINCE');
            }

    }
    public function displayAddNewForm($oModel) {
        $this->initTemplate($oModel);

        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/product_addnew_form.html' );

        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['product_detail']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign_file('temp_editor',PATH_TEMPLATE_ADMIN.'html/temp_editor_product.html' );
        $this->oTemp->assign_file('temp_product_js',PATH_TEMPLATE_ADMIN.'html/product_js.html' );
        $this->oTemp->assign('toobar_save','save_new_product()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel','?sMod=product_index');
        $this->oTemp->parse('main.toobar_cancel');

        //
        $this->oTemp->assign("enableOrDisableDivTag","enableOrDisableDivTag('bank_name_div')");
        $this->oTemp->assign("checked_product_description_swich_0","checked");
        $this->oTemp->assign("product_product_status_Other","checked");
        //$this->oTemp->assign('product_qty',1);
    //$this->oTemp->parse("main.enableOrDisableDivTag");
    }

    public function displayEditProductIndex($oModel) {
        $this->initTemplate($oModel);

        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/product_addnew_form.html' );

        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['product_detail']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign_file('temp_editor',PATH_TEMPLATE_ADMIN.'html/temp_editor_product.html' );
        $this->oTemp->assign_file('temp_product_js',PATH_TEMPLATE_ADMIN.'html/product_js.html' );
        $this->oTemp->assign('toobar_save','save_new_product()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel','?sMod=product_index&pUser='.$_REQUEST['page']);
        $this->oTemp->parse('main.toobar_cancel');
    }
    public function displayEditProductDefaul($oModel) {
        $this->initTemplate($oModel);

        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/product_addnew_form_defaul.html' );

        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['product_detail']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign_file('temp_editor',PATH_TEMPLATE_ADMIN.'html/temp_editor_product.html' );
        $this->oTemp->assign_file('temp_product_js',PATH_TEMPLATE_ADMIN.'html/product_js.html' );
        $this->oTemp->assign('toobar_save','save_new_product_defaul()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel','?sMod=product_index&pUser='.$_REQUEST['page']);
        $this->oTemp->parse('main.toobar_cancel');
    }
    public function displayFindProductIndex($oModel) {
        $this->initTemplate($oModel);

        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/product_addnew_form.html' );

        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['product_detail']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign_file('temp_editor',PATH_TEMPLATE_ADMIN.'html/temp_editor_product.html' );
        $this->oTemp->assign_file('temp_product_js',PATH_TEMPLATE_ADMIN.'html/product_js.html' );
        $this->oTemp->parse('main.div_pro_id_search');
        $this->oTemp->assign('toobar_save','save_new_product()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel','?sMod=product_index');
        $this->oTemp->parse('main.toobar_cancel');

        $rs=$this->displayListTemplate($oModel,'');
        $this->displayTemplate($oModel,$rs);
    }

    public function displayBlankProductIndex($oModel) {
        $this->initTemplate($oModel);

        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/product_addnew_form.html' );

        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['product_detail']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign_file('temp_editor',PATH_TEMPLATE_ADMIN.'html/temp_editor_product.html' );
        $this->oTemp->assign_file('temp_product_js',PATH_TEMPLATE_ADMIN.'html/product_js.html' );
        $this->oTemp->parse('main.div_pro_id_search');
        $this->oTemp->assign('toobar_save','save_new_product()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel','?sMod=product_index');
        $this->oTemp->parse('main.toobar_cancel');

        $rs=$this->displayListTemplate($oModel,'');
    }

    public function displayInfoProductDefaul($oModel) {
        $rowProduct = $oModel->getInfoProductDefaul($this->userID);
        $this->oTemp->assign('setInitializeAddNew','setInitializeEdit();');

        $this->showGUI_EditProduct($oModel,$rowProduct[0]);
        $this->assignExtract($rowProduct[0]);
        return $rowProduct;
    }
    public function displayInfoProduct($oModel) {
        $rowProduct = $oModel->getInfoProduct();
        //Show GUI
        $this->oTemp->assign('setInitializeAddNew','setInitializeEdit();');
        $this->listImageOfThisP($oModel,$rowProduct['product_id'],$rowProduct);

        $this->showGUI_EditProduct($oModel,$rowProduct);

        $rs=$oModel->getCatRootPath_Step1($rowProduct['product_category_id']);
        if(is_array($rs)) {

            $row_path='';
            foreach($rs as $row) {
                $row_path=$row['product_category_name']." / ".$row_path;
            }
        }
        $rowProduct['path_category']=$row_path;

        if($rowProduct['product_description_swich']==1) {
            $rowProduct['product_description_on_mobile_unactive']=$rowProduct['product_description_on_mobile'];
            unset($rowProduct['product_description_on_mobile']);
        }
	

        $row_def = $oModel->getProductDefault($this->userID);
        if(($rowProduct['product_prices_start'] == '') || ($rowProduct['product_prices_start'] == 0))
                $rowProduct['product_prices_start'] = $row_def['product_price'];
        else $rowProduct['product_prices_start'] = $rowProduct['product_prices_start'];
        if(($rowProduct['product_qty'] == '') || ($rowProduct['product_qty'] == 0))
                $rowProduct['product_qty'] = $row_def['product_qty'];
        else $rowProduct['product_qty'] = $rowProduct['product_qty'];
        $this->assignExtract($rowProduct);
        return $rowProduct;
    }

    public function listImageOfThisP($oModel,$pictures_product_id,$rowProduct) {

    //$getAllImage_db = $oModel->getImage($pictures_product_id);
        $getAllImage_db[1]['pictures_file_name']=$rowProduct['product_picture1'];
        $getAllImage_db[2]['pictures_file_name']=$rowProduct['product_picture2'];
        $getAllImage_db[3]['pictures_file_name']=$rowProduct['product_picture3'];
        $getAllImage_db[1]['pictures_comment']=$rowProduct['product_picture_comment1'];
        $getAllImage_db[2]['pictures_comment']=$rowProduct['product_picture_comment2'];
        $getAllImage_db[3]['pictures_comment']=$rowProduct['product_picture_comment3'];
        $count = 0;
        $i=0;
        //$comment_Product_Array = explode("139211",$rowProduct['product_pictures_comment']);
        if (is_array($getAllImage_db)) {
            $count = count($getAllImage_db);
            foreach ($getAllImage_db as $item_Image) {
                $item_Image["pictures"] = show_Picture($item_Image["pictures_file_name"]);
                //$item_Image["pictures_comment"]=$comment_Product_Array[$i];
                $i++;
                $item_Image["i"] = $i;
                $this->oTemp->assign("IMAGE_PRODUCT",$item_Image);
                $this->oTemp->parse('main.CURRENT_IMAGE_PRODUCT.IMAGE_PRODUCT');

            }
            $this->oTemp->parse('main.CURRENT_IMAGE_PRODUCT');
        }
        $this->oTemp->assign("count_current_image",$count);

    }
    public function showGUI_EditProduct($oModel,$rowProduct) {
        $this->oTemp->assign("pUser",$_REQUEST['page']);
        if ($rowProduct["product_description_normal"] ==1 || $rowProduct["product_description_normal"] =="1")
            $this->oTemp->assign("setTabInitialize","setTabInitialize_Edit('tabber_Enter_normal','tabber_Enter_HTML_tag',0,1)");
        else
            $this->oTemp->assign("setTabInitialize","setTabInitialize_Edit('tabber_Enter_HTML_tag','tabber_Enter_normal',1,0)");


        if ($rowProduct["product_description_swich"] ==1 || $rowProduct["product_description_swich"] =="1") {
            $this->oTemp->assign("checked_product_description_swich_1",'checked="checked"');
            $this->oTemp->parse('main.checked_product_description_swich_1');
            $this->oTemp->assign("change_tab","change_tab('mobile_version_des_div_disable','mobile_version_des_div_enable');");
            $this->oTemp->parse('main.change_tab');
        }
        else {
            $this->oTemp->assign("checked_product_description_swich_0","checked='checked'");
            $this->oTemp->assign("checked_product_description_swich_1","");
            $this->oTemp->assign("change_tab","change_tab('mobile_version_des_div_enable','mobile_version_des_div_disable')");

        }
        //holy shit, know very bad, but still write :D
		$sql_new = "SELECT * FROM ams_product_defaul WHERE 1 = 1";
		$rs_new = mysql_query($sql_new);
		$row_new = mysql_fetch_array($rs_new);
        $arrayListProvince = $oModel->getListProvince();
        //print_r($arrayListProvince);
        if (is_array($arrayListProvince)) {
            $checked_province_code=false;
            foreach ($arrayListProvince as $itemProvince) {
                if ($itemProvince["province_code"] == $row_new["product_province_id"]) {
                    $itemProvince["checked_province_code"] = 'selected';
                    $checked_province_code=true;
                }else {
                    $itemProvince["checked_province_code"] = "";
                }
                $this->oTemp->assign("PROVINCE",$itemProvince);
                $this->oTemp->parse('main.PROVINCES');
            }
            if($checked_province_code==false) {
                $this->oTemp->parse('main.default_province_code');
            }
        }
        if ($rowProduct["product_who_bear_the_CsOfTr"] ==1 || $rowProduct["product_who_bear_the_CsOfTr"] =="1" || $rowProduct["product_who_bear_the_CsOfTr"]=="") {
            $this->oTemp->assign("checked_product_who_bear_the_CsOfTr_1","checked");
            $this->oTemp->assign("checked_product_who_bear_the_CsOfTr_0","");
        }else {
            $this->oTemp->assign("checked_product_who_bear_the_CsOfTr_0","checked");
            $this->oTemp->assign("checked_product_who_bear_the_CsOfTr_1","");
        }
		
        if ($rowProduct["product_payment_of_goods_boa"] == 1 || $rowProduct["product_payment_of_goods_boa"] == "1") {
            $this->oTemp->assign("checked_product_payment_of_goods_boa_1",'checked="checked"');
            $this->oTemp->assign("checked_product_payment_of_goods_boa_0","");
        }else {
            $this->oTemp->assign("checked_product_payment_of_goods_boa_0",'checked="checked"');
            $this->oTemp->assign("checked_product_payment_of_goods_boa_1","");
        }
        if($rowProduct["product_periods"]!="") {
            $this->oTemp->assign("product_periods_checked".$rowProduct["product_periods"],"selected='selected'");
        }
        if ($rowProduct["product_payment_method"] ==1 || $rowProduct["product_payment_method"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_payment_method","checked");
            $this->oTemp->assign("enableOrDisableDivTag","");
        }else {
            $this->oTemp->assign("checked_product_payment_method","");
            $this->oTemp->assign("enableOrDisableDivTag","enableOrDisableDivTag('bank_name_div')");
        }

        if ($rowProduct["product_send_cash"] ==1 || $rowProduct["product_send_cash"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_send_cash","checked");
        }

        if ($rowProduct["product_use_yahoo"] ==1 || $rowProduct["product_use_yahoo"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_use_yahoo","checked");
        }else {
            $this->oTemp->assign("checked_product_use_yahoo","");
            $this->oTemp->assign("enableOrDisableDivTag_setLink","enableOrDisableDivTag('set_link_to_price_list_page');");
        }
        if ($rowProduct["product_yahoo_point"] ==1 || $rowProduct["product_yahoo_point"] =="1") {// product_yahoo_point
            $this->oTemp->assign("checked_product_yahoo_point","checked");
        }else
            $this->oTemp->assign("checked_product_yahoo_point","");

        if ($rowProduct["product_set_link_to_price_list_page"] ==1 || $rowProduct["product_set_link_to_price_list_page"] =="1") {// payment is bank
            $this->oTemp->assign("product_set_link_to_price_list_page_1","checked");
            $this->oTemp->assign("product_set_link_to_price_list_page_0","");
        }else {
            $this->oTemp->assign("product_set_link_to_price_list_page_0","checked");
            $this->oTemp->assign("product_set_link_to_price_list_page_1","");
        }


        if ($rowProduct["product_POD"] ==1 || $rowProduct["product_POD"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_POD","checked");
        }
        if ($rowProduct["product_credit_card"] ==1 || $rowProduct["product_credit_card"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_credit_card","checked");
        }
        // checked status product(second hand ==1 ; new ==2 ; other ==3)
        
        if (intval($rowProduct["product_product_status"])==1 || $rowProduct["product_product_status"]=="") {// payment is bank
            $this->oTemp->assign("product_product_status_SecondHand","checked='checked'");
            $this->oTemp->assign("product_product_status_New","");
            $this->oTemp->assign("product_product_status_Other","");
        }elseif (intval($rowProduct["product_product_status"])==2 ) {
            $this->oTemp->assign("product_product_status_SecondHand","");
            $this->oTemp->assign("product_product_status_New","checked");
            $this->oTemp->assign("product_product_status_Other","");
        } else {
            $this->oTemp->assign("product_product_status_SecondHand","");
            $this->oTemp->assign("product_product_status_New","");
            $this->oTemp->assign("product_product_status_Other","checked");
        }

        if ($rowProduct["product_ability_to_return_product"] ==1 || $rowProduct["product_ability_to_return_product"] =="1") {// payment is bank
            $this->oTemp->assign("checked_ability_to_return_product_1",'checked="checked"');
            $this->oTemp->assign("checked_ability_to_return_product_0","");
        }
        else {
            $this->oTemp->assign("checked_ability_to_return_product_0",'checked="checked"');
            $this->oTemp->assign("checked_ability_to_return_product_1","");
        }
		/*
        if ($rowProduct["product_limited_assesment_of_the_bidder"] ==1 || $rowProduct["product_limited_assesment_of_the_bidder"] =="1") {// payment is bank
            $this->oTemp->assign("checked_limited_assesment_of_the_bidder","checked");
        }
        */
        $index_ = $rowProduct["product_limited_assesment_of_the_bidder"] + 2; 
        $this->oTemp->assign("product_limited_assesment_of_the_bidder_selected_".$index_,'selected=selected');
        if ($rowProduct["product_auto_extend"] ==1 || $rowProduct["product_auto_extend"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_auto_extend","checked");
        }
        if ($rowProduct["product_end_soon"] ==1 || $rowProduct["product_end_soon"] =="1") {// payment is bank
            $this->oTemp->assign("cheked_product_end_soon","checked");
        }
        if ($rowProduct["product_have_to_negotiate_discount"] ==1 || $rowProduct["product_have_to_negotiate_discount"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_have_to_negotiate_discount","checked");
        }
        //Thanhbx---
        $check_key = false;
        for($i=1;$i<=5;$i++) {
            if($i == $rowProduct["product_key_select"]) {
                $this->oTemp->assign("checked_store".$i,'checked="checked"');
                $check_key=true;
            }
            $this->oTemp->assign("product_key".$i,$rowProduct['product_key'.$i]);
        }
        if(!$check_key) {
            $this->oTemp->assign("checked_store0",'checked="checked"');
        }

        if ($rowProduct["product_title_bold_line"] ==1 || $rowProduct["product_title_bold_line"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_title_bold_line","checked");
        }

        if ($rowProduct["product_bakground_color"] ==1 || $rowProduct["product_bakground_color"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_bakground_color","checked");
        }
        if ($rowProduct["product_store_hot_auction"] ==1 || $rowProduct["product_store_hot_auction"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_store_hot_auction","checked");
        }
        if ($rowProduct["product_icon_gift"] ==1 || $rowProduct["product_icon_gift"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_icon_gift","checked");
        }

        if ($rowProduct["product_affiliate"] ==1 || $rowProduct["product_affiliate"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_affiliate","checked");
        }
        if ($rowProduct["product_transport_goods_abroad"] ==1 || $rowProduct["product_transport_goods_abroad"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_transport_goods_abroad","checked");
        }
        if ($rowProduct["product_person"] ==1 || $rowProduct["product_person"] =="1") {// payment is bank
            $this->oTemp->assign("checked_product_person","checked");
        }
		
        //product_set_limit_on_prices
        $this->oTemp->assign("product_set_limit_on_prices_s","selectedValueOfSelectbox('product_set_limit_on_prices','{$rowProduct['product_set_limit_on_prices']}')");
        $this->oTemp->assign("product_time_auction_s","selectedValueOfSelectbox('product_time_auction','{$rowProduct['product_time_auction']}')");
        $this->oTemp->assign("product_time_auction_end_s","selectedValueOfSelectbox('product_time_auction_end','{$rowProduct['product_time_auction_end']}')");

        $this->oTemp->assign("product_auto_open_aution_s","selectedValueOfSelectbox('product_auto_open_aution','{$rowProduct['product_auto_open_aution']}')");
        $this->oTemp->assign("product_size_after_packet_s","selectedValueOfSelectbox('product_size_after_packet','{$rowProduct['product_size_after_packet']}')");
        $this->oTemp->assign("product_weight_after_packet_s","selectedValueOfSelectbox('product_weight_after_packet','{$rowProduct['product_weight_after_packet']}')");
        $this->oTemp->assign("product_icon_highlight_s","selectedValueOfSelectbox('product_icon_highlight','{$rowProduct['product_icon_highlight']}')");

    }

    public function resultXML_filterProduct($oModel) {
        $rerult = $oModel->filterProduct();
        $RES='';
        if (is_array($rerult)) {
            foreach ($rerult as $itemProduct) {

                if ($itemProduct["product_yahoo_point"]==1 || $itemProduct["product_yahoo_point"]=="1")
                    $itemProduct["product_yahoo_point_checked"] = "checked";
                if ($itemProduct["product_icon_gift"]==1 || $itemProduct["product_icon_gift"]=="1")
                    $itemProduct["product_icon_gift_checked"] = "checked";
                if ($itemProduct["product_icon_highlight"]==1 || $itemProduct["product_icon_highlight"]=="1")
                    $itemProduct["product_icon_highlight_checked"] = "checked";
                if ($itemProduct["product_store_hot_auction"]==1 || $itemProduct["product_store_hot_auction"]=="1")
                    $itemProduct["product_store_hot_auction_checked"] = "checked";
                if ($itemProduct["product_bakground_color"]==1 || $itemProduct["product_bakground_color"]=="1")
                    $itemProduct["product_bakground_color_checked"] = "checked";
                if ($itemProduct["product_title_bold_line"]==1 || $itemProduct["product_title_bold_line"]=="1")
                    $itemProduct["product_title_bold_line_checked"] = "checked";
                if ($itemProduct["product_have_to_negotiate_discount"]==1 || $itemProduct["product_have_to_negotiate_discount"]=="1")
                    $itemProduct["product_have_to_negotiate_discount_checked"] = "checked";


                if ($itemProduct["product_affiliate"]==1 || $itemProduct["product_affiliate"]=="1")
                    $itemProduct["product_remuneration_to_partner"] = $itemProduct["product_remuneration_to_partner"]."%";
                else
                    $itemProduct["product_remuneration_to_partner"] = "";

                // use yahoo point with fees
                if ($itemProduct["product_yahoo_point"]==1 || $itemProduct["product_yahoo_point"]=="1") {
                    $itemProduct["product_yahoo_point_fees"] = floatval($itemProduct["product_yahoo_point_fees"])."%";
                }
                else
                    $itemProduct["product_yahoo_point_fees"] = "";
                // icon highlight
                if ($itemProduct["product_icon_highlight"]!='' || $itemProduct["product_icon_highlight"]== null) {
                    $itemProduct["product_icon_highlight"] = '<img src="{URL_TEMPLATE_ADMIN}image/icon/'.$itemProduct["product_icon_highlight"].'" title="affiliate" align="middle" border="0"/>';
                }
                else
                    $itemProduct["product_icon_highlight"] = "";

                $this->oTemp->assign("rowProduct",$itemProduct);
                $this->oTemp->parse('main.LIST_PRODUCT.rowProduct');
            }
            $this->oTemp->parse('main.LIST_PRODUCT');
            $RES = $this->oTemp->text('main.LIST_PRODUCT');
        }
        $oJSON = new Services_JSON() ;
        echo $oJSON->encode( array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m'), ),
        'BODY' => array('RES' => $RES
        )) ) ;

    }
    public function resultXML_AJAX_GET_INFOR($oModel,$product_id) {
        $rerult = $oModel->get_infor_pid($product_id);
        if (is_array($rerult)) {
            foreach ($rerult as $itemProduct) {
                $pictures_product_id = $itemProduct['product_id'];
                $itemProduct['image_string_special'] = $this->imageOfThisP_Ajax($oModel,$pictures_product_id);
                $cacheData = $this->displayListOMoT_AJAX($oModel,$pictures_product_id);
                $itemProduct['string'] = $cacheData['string'];
                //$atrributeArray = $this->showAttributeAjax($oModel,$pictures_product_id);
                $atrribute=$this->ajax_showChildAtt($oModel,$pictures_product_id);

                $itemProduct['RES'] = 1;
                $itemProduct['product_id_search'] = $itemProduct['product_id'] ;

                if($itemProduct['product_description_swich']==1) {
                    $itemProduct['product_description_on_mobile_unactive']=$itemProduct['product_description_on_mobile'];
                //unset($itemProduct['product_description_on_mobile']);
                }
                //$RES = array_merge($itemProduct,$atrributeArray);
                /**
                 * Return category path
                 */
                $rs=$oModel->getCatRootPath_Step1($itemProduct['product_category_id']);
                if(is_array($rs)) {

                    $row_path='';
                    foreach($rs as $row) {
                        $row_path=$row['product_category_name']." / ".$row_path;
                    }
                }
                //$itemProduct['path_category']=$row_path;
                /**
                 * Return div of product bank
                 */
                $bank_name_div=$this->displayBlockProductBankInputWithData($itemProduct['product_bank']);

                /**
                 *
                 */
                $other_payment_method_div=$this->displayBlockOtherPayMentMethodWithData($itemProduct['product_other_payment_method']);


                $RES=$itemProduct;
            }


        }
        else {
            $RES['RES'] = null;
        }

        $oJSON = new Services_JSON() ;
        echo $oJSON->encode( array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m'), ),
        'BODY' => $RES,
        'innerData'=>$cacheData['innerData'],
        'att_pro'=>$atrribute,
        'path_cat'=>$row_path,
        'bank_name_div'=>$bank_name_div,
        'other_payment_div'=>$other_payment_method_div
        ) ) ;


    }
    public function imageOfThisP_Ajax($oModel,$pictures_product_id) {
        $oModel->setData('product_id', $pictures_product_id);
        $rowProduct = $oModel->getInfoProduct();
        $getImages[1]['pictures_file_name']=$rowProduct['product_picture1'];
        $getImages[2]['pictures_file_name']=$rowProduct['product_picture2'];
        $getImages[3]['pictures_file_name']=$rowProduct['product_picture3'];
        $getImages[1]['pictures_comment']=$rowProduct['product_picture_comment1'];
        $getImages[2]['pictures_comment']=$rowProduct['product_picture_comment2'];
        $getImages[3]['pictures_comment']=$rowProduct['product_picture_comment3'];
        $count = 0;
        $i=0;
        $RES=null;
        if (is_array($getImages)) {
            $count = count($getImages);
            foreach ($getImages as $item_Image) {
                $i++;
                $item_Image["pictures"] = show_Picture($item_Image["pictures_file_name"]);
                $item_Image["i"] = $i;
                $this->oTemp->assign("IMAGE_PRODUCT",$item_Image);
                $this->oTemp->parse('main.CURRENT_IMAGE_PRODUCT.IMAGE_PRODUCT');

            }
            $this->oTemp->parse('main.CURRENT_IMAGE_PRODUCT');
            $RES = $this->oTemp->text('main.CURRENT_IMAGE_PRODUCT');

        }
        return $RES;

		/*$oJSON = new Services_JSON() ;
	  	echo $oJSON->encode( array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m'), ),
		  			  'BODY' => array('RES' => $RES
		  			  				  )) ) ;*/


    }
    public function filterProduct($oModel) {
        $rerult = $oModel->filterProduct();
        $RES='';
        if (is_array($rerult)) {
            $this->oTemp->assign("page",$_REQUEST['pUser']);

            foreach ($rerult as $itemProduct) {

                if ($itemProduct["product_yahoo_point"]==1 || $itemProduct["product_yahoo_point"]=="1")
                    $itemProduct["product_yahoo_point_checked"] = "checked";
                if ($itemProduct["product_icon_gift"]==1 || $itemProduct["product_icon_gift"]=="1")
                    $itemProduct["product_icon_gift_checked"] = "checked";
                if ($itemProduct["product_store_hot_auction"]==1 || $itemProduct["product_store_hot_auction"]=="1")
                    $itemProduct["product_store_hot_auction_checked"] = "checked";
                if ($itemProduct["product_bakground_color"]==1 || $itemProduct["product_bakground_color"]=="1")
                    $itemProduct["product_bakground_color_checked"] = "checked";
                if ($itemProduct["product_title_bold_line"]==1 || $itemProduct["product_title_bold_line"]=="1")
                    $itemProduct["product_title_bold_line_checked"] = "checked";
                if ($itemProduct["product_have_to_negotiate_discount"]==1 || $itemProduct["product_have_to_negotiate_discount"]=="1")
                    $itemProduct["product_have_to_negotiate_discount_checked"] = "checked";


                if ($itemProduct["product_affiliate"]==1 || $itemProduct["product_affiliate"]=="1")
                    $itemProduct["product_remuneration_to_partner"] = $itemProduct["product_remuneration_to_partner"]."%";
                else
                    $itemProduct["product_remuneration_to_partner"] = "";

                // use yahoo point with fees
                if ($itemProduct["product_yahoo_point"]==1 || $itemProduct["product_yahoo_point"]=="1") {
                    $itemProduct["product_yahoo_point_fees"] = floatval($itemProduct["product_yahoo_point_fees"])."%";
                }
                else
                    $itemProduct["product_yahoo_point_fees"] = "";
                // icon highlight
                if (strlen($itemProduct["product_icon_highlight"])>3) {
                    $itemProduct["product_icon_highlight"] = '<img src="{URL_TEMPLATE_ADMIN}image/icon/'.$itemProduct["product_icon_highlight"].'" title="affiliate" align="middle" border="0"/>';
                }
                else
                    $itemProduct["product_icon_highlight"] = "";
                if($itemProduct['product_picture1'] != ''){
                    if(file_exists(PATH_UPLOAD_PRODUCT.FOLDER_THUMB.$itemProduct['product_picture1'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT_THUMB.$itemProduct['product_picture1'];
                    }elseif(file_exists(PATH_UPLOAD_PRODUCT.$itemProduct['product_picture1'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT.$itemProduct['product_picture1'];
                    }
                }elseif($itemProduct['product_picture2'] != ''){
                    if(file_exists(PATH_UPLOAD_PRODUCT.FOLDER_THUMB.$itemProduct['product_picture2'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT_THUMB.$itemProduct['product_picture2'];
                    }elseif(file_exists(PATH_UPLOAD_PRODUCT.$itemProduct['product_picture2'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT.$itemProduct['product_picture2'];
                    }
                }elseif($itemProduct['product_picture3'] != ''){
                    if(file_exists(PATH_UPLOAD_PRODUCT.FOLDER_THUMB.$itemProduct['product_picture3'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT_THUMB.$itemProduct['product_picture3'];
                    }elseif(file_exists(PATH_UPLOAD_PRODUCT.$itemProduct['product_picture3'])){
                        $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT.$itemProduct['product_picture3'];
                    }
                }else{
                    $itemProduct['product_thumb'] = URL_UPLOAD_PRODUCT.'no_image.gif';
                }
                
                $_SESSION['last_filterProduct'][]=$itemProduct;

                $product_key_select = $itemProduct['product_key_select'];
                if($product_key_select > 0){
                    $itemProduct['product_key'] = $itemProduct["product_key".$product_key_select];
                }else{
                    $itemProduct['product_key'] = '';
                }

                $this->oTemp->assign("rowProduct",$itemProduct);
                $this->oTemp->parse('main.LIST_PRODUCT.rowProduct');
            }
            $this->oTemp->parse('main.LIST_PRODUCT');
            $this->oTemp->assign("navigator",$oModel->oNavigator->navigator());
        }


    }

    public function displayListOMoT_Defaul($oModel,$owner_id) {
        $aData = $oModel->getOMoT_ShowEditPage_Defaul($owner_id);
        $i=0;
        if(is_array($aData)) {
            foreach ($aData as  $otherItem) {
                $i++;
                $otherItem['i']=$i;
                if (trim($otherItem['other_link_to_price_list']!='' )) {
                    $this->oTemp->assign("InitializeOMoT",'setInnerHTMLForTdSwich(1,"td2_'.$i.'",\''.$otherItem['other_link_to_price_list'].'\','.$i.')');
                }else
                    $this->oTemp->assign("InitializeOMoT",'setInnerHTMLForTdSwich(2,"td2_'.$i.'",\''.$otherItem['other_uniform_price'].'\','.$i.')');
                $this->oTemp->assign("OMoT_ROW",$otherItem);
                $this->oTemp->parse('main.OMoT.OMoT_ROW');
            }
            $this->oTemp->parse('main.OMoT');
        }

    }
    public function displayListOMoT($oModel,$product_id) {
        $aData = $oModel->getOMoT_ShowEditPage($product_id);
        $i=0;
        if(is_array($aData)) {
            foreach ($aData as  $otherItem) {
                $i++;
                $otherItem['i']=$i;
                if (trim($otherItem['other_link_to_price_list']!='' )) {
                    $this->oTemp->assign("InitializeOMoT",'setInnerHTMLForTdSwich(1,"td2_'.$i.'",\''.$otherItem['other_link_to_price_list'].'\','.$i.')');
                }else
                    $this->oTemp->assign("InitializeOMoT",'setInnerHTMLForTdSwich(2,"td2_'.$i.'",\''.$otherItem['other_uniform_price'].'\','.$i.')');
                $this->oTemp->assign("OMoT_ROW",$otherItem);
                $this->oTemp->parse('main.OMoT.OMoT_ROW');
            }
            $this->oTemp->parse('main.OMoT');
        }

    }
    public function displayListOMoT_AJAX($oModel,$product_id) {
        $aData = $oModel->getOMoT_ShowEditPage($product_id);
        $i=0;
        if (is_array($aData)) {
            $aDataForSetInnerHTMl = array();

            foreach ($aData as  $otherItem) {
                $i++;
                $otherItem['i']=$i;
                $tdId = "td2_".$i;

                if (trim($otherItem['other_link_to_price_list']!='' )) {$swich=1;
                    $valueShow	= $otherItem['other_link_to_price_list'];
                }else {
                    $swich=2;
                    $valueShow	= $otherItem['other_uniform_price'];
                }

                $dataToCallF = 	  array(0=>$swich,
                    1=>$tdId,
                    2=>$valueShow,
                    3=>$i);
                array_push($aDataForSetInnerHTMl,$dataToCallF);

                $this->oTemp->assign("OMoT_ROW",$otherItem);
                $this->oTemp->parse('main.OMoT.OMoT_ROW');
            }

            $this->oTemp->parse('main.OMoT');
            $string = $this->oTemp->text('main.OMoT');
            $return = array("string"=>$string,
                "innerData"=>$aDataForSetInnerHTMl);
            return $return;
        }
        return '';
    }

/*******************************************************************************************************************************************
* TEMPLATE
*******************************************************************************************************************************************/
	public function readFile( $sFile ) {
        $oFt = fopen($sFile, 'r');
        $iFileSize = filesize($sFile);
        if($iFileSize > 0)
            $sContent = fread($oFt, $iFileSize);
        else
            $sContent = '';
        fclose($oFt);
        return $sContent;
    }
	
    public function displayListTemplate($oModel, $row_pro) {
	$arr = array( array('name'=>'New','value'=>'New'),
                        array('name'=>'SP','value'=>'SP'),
                        array('name'=>'A','value'=>'A'),
                        array('name'=>'B','value'=>'B')
                    );
        $userInfo = $oModel->getUserInfo($row_pro['owner_id']);
        $rs = $oModel->getListTemplate();
        $id = "";
        $aTpl = Array();
        if(is_array($rs)) {
            $num = 0;
            //print_r($rs);
            //print_r($row_pro);
            foreach($rs as $row) {
                if($row_pro['product_explanation'] == '') {
                    if($userInfo['admin_template_id'] == 0){
                        if($row['active_dedault'] == 1) {
                            $row['checked']="checked";
                            $mark = $num;
                            $id = $row['id'];
                            $aTpl = $rs[$num];
                            $this->oTemp->assign('default_temp', $row['id']);
                            $this->oTemp->parse('main.loading_default');
                        }
                    }
                    else {
                        if($userInfo['admin_template_id'] ==$row['id']){
                            $row['checked']="checked";
                            $mark = $num;
                            $id = $row['id'];
                            $aTpl = $rs[$num];
                            $this->oTemp->assign('default_temp', $row['id']);
                            $this->oTemp->parse('main.loading_default');
                        }
                    }
                } else {
                    if($row_pro['product_template_id'] == $row['id']) {
                        $row['checked']="checked";
                        $id = $row['id'];
                        $this->oTemp->assign('template_chosen_id', $id);
                        if(trim($row_pro['product_rank']) != ''){
                                $this->oTemp->assign('product_rank_temp', $row_pro['product_rank']);
                        }else{
                                $sTpl_dir = PATH_UPLOAD.'template/temp'.$id.'/';
                                $this->oTemp->assign('product_rank_temp', $this->readFile($sTpl_dir.'rank.html'));
                        }
                    }
                }
                $this->oTemp->assign('div_choose_template', $row);
                $this->oTemp->parse('main.div_choose_template');
                $num++;
            }
        }
        
        if(count($aTpl) > 0){
            $aTpl['path'] = 'template/temp'.$aTpl['id']."/";
            $this->getdefaultemp('template/temp'.$id."/");

            
        }
        return $aTpl;
    }
    
    public function getdefaultemp($template_path) {
        $rs_temp['rank'] = PATH_UPLOAD.$template_path.HTML_RANK;
        $rs_temp['rank_dagame']= PATH_UPLOAD.$template_path.'dagame.html';
        $text=file_get_contents($rs_temp['rank'],true);
        $this->oTemp->assign('product_rank_temp',$text);
        $this->oTemp->parse('main.div_template_rank');

        $text=file_get_contents($rs_temp['rank_dagame'],true);
        $this->oTemp->assign("dagame_file",$text);
        $this->oTemp->parse('main.div_template_rank_dagame');
    }
    public function displayTemplateDefault($oModel, $rs, $row_product = null) {
        if($row_product['product_explanation'] == '') {
            $template_path = $rs['path'];

            $rs_temp['explanation']=PATH_UPLOAD.$template_path.HTML_EXPLANATION;
            $rs_temp['rank']=PATH_UPLOAD.$template_path.HTML_RANK;
            $rs_temp['rank_dagame']=PATH_UPLOAD.$template_path.'dagame.html';
            $rs_temp['note']=PATH_UPLOAD.$template_path.HTML_NOTE;
            $rs_temp['size']=PATH_UPLOAD.$template_path.HTML_SIZE;

            $this->oTemp->assign_file('file_temp_ex',$rs_temp['explanation']);
            $this->oTemp->parse('main.div_template_ex');

            $this->oTemp->assign_file('file_temp_rank',$rs_temp['rank']);
            $this->oTemp->parse('main.div_template_rank');

            $text = file_get_contents($rs_temp['rank_dagame'], true);
            $this->oTemp->assign("dagame_file",$text);
            //$this->oTemp->parse('main.div_template_rank_dagame');

            $this->oTemp->assign_file('file_temp_note',$rs_temp['note']);
            $this->oTemp->parse('main.div_template_note');


            $result_temp_size=$this->pre_load_template_size($oModel,$rs_temp['size'],'');
            $this->oTemp->assign('product_size',$result_temp_size);
            $this->oTemp->parse('main.product_size');
        }
    }


    public function ajax_display_template($oModel,$template_path) {
    //$this->oTemp->setTemplatePath('')

        $rs_temp['explanation']=PATH_UPLOAD.$template_path.HTML_EXPLANATION;
        $rs_temp['rank']=PATH_UPLOAD.$template_path.HTML_RANK;
        $rs_temp['rank_dagame']=PATH_UPLOAD.$template_path.'dagame.html';
        $rs_temp['note']=PATH_UPLOAD.$template_path.HTML_NOTE;
        $rs_temp['size']=PATH_UPLOAD.$template_path.HTML_SIZE;


        $this->oTemp->assign_file('file_temp_ex',$rs_temp['explanation']);
        $this->oTemp->parse('main.div_template_ex');
        $result_temp_ex=$this->oTemp->text('main.div_template_ex');


        $this->oTemp->assign_file('file_temp_rank',$rs_temp['rank']);
        $this->oTemp->parse('main.div_template_rank');
        $result_temp_rank=$this->oTemp->text('main.div_template_rank');

        //$this->oTemp->assign_file('file_temp_rank_dagame',$rs_temp['rank_damage']);
        $text=file_get_contents($rs_temp['rank_dagame'],true);
        //$this->oTemp->assign("dagame_file",$text);
        //$this->oTemp->parse('main.div_template_rank_dagame');
        $result_temp_rank_dagame=$this->oTemp->text('main.div_template_rank_dagame');

        $this->oTemp->assign_file('file_temp_note',$rs_temp['note']);
        $this->oTemp->parse('main.div_template_note');
        $result_temp_note=$this->oTemp->text('main.div_template_note');

        $this->oTemp->assign_file('file_temp_size',$rs_temp['size']);
        $this->oTemp->parse('main.div_template_size');
        //$result_temp_size=$this->oTemp->text('main.div_template_size');

        $result_temp_size=$this->pre_load_template_size($oModel,$rs_temp['size'],'');


        $oJSON = new Services_JSON();
        echo $oJSON->encode(array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m:s'), ),
        'BODY' => array('temp_ex' => $result_temp_ex,
        'temp_rank' => $result_temp_rank,
        'temp_rank_dagame' => $result_temp_rank_dagame,
        'temp_note' => $result_temp_note,
        'temp_size' => $result_temp_size )));
    }

    public function pre_load_template_size($oModel,$path_file,$size_id) {
        $oView_temp=new View_Admin_Index_Template($oModel);
        $oView_temp->setTemplate($path_file);
        //FIRST TIME DISPLAY,GET THE TOP SIZE OPTION
        if($size_id=='') {
            $rs = $oModel->getListSize();
            
            if(is_array($rs)) {
                $oView_temp->oTemp->assign('block_product_size',$rs[0]);
                $oView_temp->oTemp->parse('div_temp_size.block_product_size');
                $oView_temp->oTemp->parse('div_temp_size');
                return $oView_temp->oTemp->text('div_temp_size');
            }
        }  else {
            $rs = $oModel->getSizeDetail($size_id);
            
            if(is_array($rs)) {
                $oView_temp->oTemp->assign('block_product_size',$rs);
                $oView_temp->oTemp->parse('div_temp_size.block_product_size');
                $oView_temp->oTemp->parse('div_temp_size');
                return $oView_temp->oTemp->text('div_temp_size');
            }
        }

    }


    public function ajax_change_size($oModel, $template_path, $size_id) {
        $rs_temp['size'] = PATH_UPLOAD.$template_path.HTML_SIZE;
        $rs_temp['display_size'] = $this->pre_load_template_size($oModel,$rs_temp['size'],$size_id);

        $oJSON = new Services_JSON();
        echo $oJSON->encode(array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m:s'), ),
        'BODY' => array('display_size' => $rs_temp['display_size'] )));
    }

    public function display_list_size_edit($oModel,$size_id) {
        $rs = $oModel->getAllAttParr();
        if(is_array($rs)) {
            foreach($rs as $row) {
                if($size_id!='') {
                    if($row['at_id']==$size_id) {
                        $row['checked']='checked';
                    }
                }
                $this->oTemp->assign('PARRENT_ATTRIBUTE',$row);
                $this->oTemp->parse('main.PARRENT_ATTRIBUTE');
            }
        }

    }

    public function displayRank($oModel,$rank_name,$condition="") {
        $arr=array( array('name'=>'New','value'=>'New'),
            array('name'=>'SP','value'=>'SP'),
            array('name'=>'A','value'=>'A'),
            array('name'=>'B','value'=>'B'));
					/*
					array('name'=>'C','value'=>'C'),
					array('name'=>'D','value'=>'D'),
					array('name'=>'E','value'=>'E')
					*/
		foreach($arr as $row) {
			if(!in_array($rank_name, $row)){
				$this->oTemp->assign('norank_checked', 'checked="checked"');
			}
            if($rank_name=='') {
                if($row['name']=='A')
                    $row['checked']='checked';
            }
            else {
                if($row['name']==$rank_name)
                    $row['checked']='checked';
            }
            $this->oTemp->assign('div_rank_name',$row);
            $this->oTemp->parse('main.div_rank_name');
        }
        $row=array();
        for($i=1;$i<5;$i++) {
            if($condition==$i) {
                $row['checked']='checked';
            }
            else {
                $row['checked']='';
                if($condition=="" && $i==1) {
                    $row['checked']='checked';
                }
            }
            $row['name']=$i;
            $row['value']=$i;

            $this->oTemp->assign('div_condition',$row);
            $this->oTemp->parse('main.div_condition');
        }

    }

    /**
     * Display transfer method
     */
    public function displayBlockProductBankInputDefault($oModel) {
        for($i=0;$i<=9;$i++) {
            $row['num']=$i;
            if($i==0) {
                $row['display']='block';
            }
            else {
                $row['display']='none';
            }
            $this->oTemp->assign('div_product_bank',$row);
            $this->oTemp->parse('main.parent_div_product_bank.div_product_bank');

            //OTHER METHOD
            $this->oTemp->assign('div_product_other_payment_method',$row);
            $this->oTemp->parse('main.parent_div_product_other_payment_method.div_product_other_payment_method');
        }
        $this->oTemp->assign('now_div_blank_id',"1");
        $this->oTemp->parse('main.parent_div_product_bank.now_div_blank_id');
        $this->oTemp->parse('main.parent_div_product_bank');

        $this->oTemp->assign('bank_name_div_display','none');
        $this->oTemp->parse('main.bank_name_div_display');

        //OTHER METHOD
        $this->oTemp->parse('main.parent_div_product_other_payment_method');
    }

    public function displayBlockProductBankInputWithData($aData) {
        $num=0;
        if($aData!='' && $aData!=null) {	
        	$rs=explode('>*',$aData);
            if(is_array($rs)) {

                foreach($rs as $row) {
                    $arr[]['product_bank']=$row;
                }

                foreach($arr as $arr_row) {
                    $arr_row['display']='block';
                    $arr_row['num']=$num;
                    $this->oTemp->assign('div_product_bank',$arr_row);
                    $this->oTemp->parse('main.parent_div_product_bank.div_product_bank');
                    $num++;
                }
            }
        }
        for($i=$num;$i<=9;$i++) {
            $row1['display']='none';
            $row1['num']=$i;
            $this->oTemp->assign('div_product_bank',$row1);
            $this->oTemp->parse('main.parent_div_product_bank.div_product_bank');
        }

        $this->oTemp->assign('now_div_blank_id',$num);
        $this->oTemp->parse('main.parent_div_product_bank.now_div_blank_id');
        $this->oTemp->parse('main.parent_div_product_bank');

        //DISPLAY THE DIV Wrapper
        $this->oTemp->assign('bank_name_div_display','block');
        $this->oTemp->parse('main.bank_name_div_display');

        return $this->oTemp->text('main.parent_div_product_bank');
    }

    public function displayBlockOtherPayMentMethodWithData($aData) {
        $num=0;
        if($aData!='' && $aData!=null) {
            $rs=explode('>*',$aData);
            if(is_array($rs)) {
                foreach($rs as $row) {
                    $arr[]['product_other_payment_method']=$row;
                }
                foreach($arr as $arr_row) {

                    $arr_row['display']='block';
                    $arr_row['num']=$num;
                    $this->oTemp->assign('div_product_other_payment_method',$arr_row);
                    $this->oTemp->parse('main.parent_div_product_other_payment_method.div_product_other_payment_method');
                    $num++;
                }
            }
        }

        for($i=$num;$i<=9;$i++) {
            if($i==0) {
                $row1['display']='block';
            }
            else {
                $row1['display']='none';
            }
            $row1['num']=$i;
            $this->oTemp->assign('div_product_other_payment_method',$row1);
            $this->oTemp->parse('main.parent_div_product_other_payment_method.div_product_other_payment_method');
        }

        $this->oTemp->assign('now_other_method_transfer',$num);
        $this->oTemp->parse('main.parent_div_product_other_payment_method.now_other_method_transfer');
        $this->oTemp->parse('main.parent_div_product_other_payment_method');

        return $this->oTemp->text('main.parent_div_product_other_payment_method');
    }
}